//
//  ZDBUpdateNameViewController.m
//  ZDB
//
//  Created by 微笑吧阳光 on 2020/3/28.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBUpdateNameViewController.h"

@interface ZDBUpdateNameViewController ()

@end

@implementation ZDBUpdateNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.topCoastC.constant = 5;//kStatusBarAndNavigationBarHeight;
    [self.enterText addTarget:self action:@selector(changedTextField:) forControlEvents:UIControlEventEditingChanged];
    
    WEAKSELF
    [self.sureBtn add_BtnClickHandler:^(NSInteger tag) {
        STRONGSELFFor(weakSelf);
        [strongSelf updateNickNameAndHeadImage];
    }];
    
    self.enterText.text = self.nicknameStr;
}

-(void)changedTextField:(UITextField *)textField
{
    [RestrictionInput restrictionInputTextField:textField maxNumber:12 showView:self.view showErrorMessage:@"0~12字符~"];
}

-(void)updateNickNameAndHeadImage{
    
    [self.view endEditing:YES];
    
    if ([self JudgeTheillegalCharacter:self.enterText.text]==YES) {
        
        [JMNotifyView showNotify:@"昵称不能包含特殊字符" isSuccessful:NO];
        return;
    }

    if (kStringIsEmpty(self.enterText.text)) {
        [JMNotifyView showNotify:@"昵称不能为空" isSuccessful:NO];
        return;
        
    }
       [self showLoadingAnimation];

       NSString  * loginurl = [[YINetWorkAPIGenerate sharedInstance] APINomark:@"user_updateNickNameAndHeadImage"];
       NSMutableDictionary * diccc = [NSMutableDictionary dictionary];
       [diccc setValue:self.enterText.text forKey:@"nikeName"];
       WEAKSELF
       [[SmileHttpTool sharedInstance] POST :loginurl parameters:diccc origin:NO success:^(NSInteger statusCode, NSString *message, id responseObject) {
         STRONGSELFFor(weakSelf)
           if (statusCode==0) {
              [JMNotifyView showNotify:@"保存成功" isSuccessful:YES];
               if (strongSelf.updetaInfoClickBlock) {
                   strongSelf.updetaInfoClickBlock(YES,strongSelf.enterText.text);
               }
              [strongSelf.navigationController popViewControllerAnimated:YES];
           }else{
              [JMNotifyView showNotify:message isSuccessful:NO];
           }
            [strongSelf stopLoadingAnimation];
       } failure:^(id responseObject, NSError *error) {
           NSLog(@"error----%@",error);
           [JMNotifyView showNotify:@"网络错误，请重试~" isSuccessful:NO];
           [self stopLoadingAnimation];
       }];

}

- (BOOL)JudgeTheillegalCharacter:(NSString *)content{
 //提示 标签不能输入特殊字符
 NSString *str =  @"^[A-Za-z0-9\\u4e00-\u9fa5]+$";
//@"^[A-Za-z0-9\\u4e00-\u9fa5]+$”;
 NSPredicate * emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", str];
 if (![emailTest evaluateWithObject:content]) {
 return YES;
 }
 return NO;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
